﻿using Microsoft.Extensions.Configuration;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace Chaunce.FrameWork.NetCore.Chaunce.Logging
{
    /// <summary>
    /// 日志初始化参数
    /// </summary>
    public class ChaunceSerilogSetting
    {
        public ChaunceSerilogSetting()
        {

        }
        /// <summary>
        /// 使用appsettings.json文件 配置加载参数
        /// </summary>
        /// <param name="configuration"></param>
        public ChaunceSerilogSetting(IConfiguration configuration)
        {
            this.Configuration = configuration;
        }
        /// <summary>
        ///.net core 一般采用此方法 使用Serilog.Settings.Configuration组件读取appsettings.json配置文件初始化
        /// </summary>
        public IConfiguration Configuration { get; set; }
        /// <summary>
        /// 记录log日志最小级别 默认是Information
        /// </summary>
        public LogEventLevel MinimumLevel { get; set; } = LogEventLevel.Debug;

        /// <summary>
        /// 日志记录的接收器类型
        /// </summary>
        public SerilogSink[] Sinks { get; set; }
        /// <summary>
        /// 应用程序名称
        /// </summary>
        public string ApplicationName { get; set; }
        /// <summary>
        /// 日志文件是否分开存放 按level级别
        /// </summary>
        public bool IsSeparateLogFile { get; set; } = true;
        /// <summary>
        /// ExceptionLess接收器参数
        /// </summary>
        public SerilogExceptionLessSetting ExceptionLessSetting { get; set; }
    }

    /// <summary>
    /// ExcepitonLess组件参数配置
    /// </summary>
    public class SerilogExceptionLessSetting
    {
        /// <summary>
        ///ExceptionLess  Api 访问key值
        /// </summary>
        public string ApiKey { get; set; }
        /// <summary>
        /// ExceptionLess 服务端url
        /// </summary>
        public string ServerUrl { get; set; }
        /// <summary>
        ///ExceptionLess记录 日志最低级别 必须>=SerilogSetting中日志记录级别
        /// </summary>
        public LogEventLevel MinimumLevel { get; set; } = LogEventLevel.Debug;
    }

    /// <summary>
    /// serilog接收器枚举
    /// </summary>
    public enum SerilogSink
    {
        /// <summary>
        ///调试窗口
        /// </summary>
        Debug = 1,
        /// <summary>
        /// 命令行
        /// </summary>
        Console = 2,
        /// <summary>
        /// 文件保存 (每天一个文件),每天记录使用json格式保存
        /// </summary>
        File = 3,
        /// <summary>
        /// ExceptionLess组件支持
        /// </summary>
        Exceptionless = 4
    }
}
